﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.Model;

namespace HuaCheng.Controller
{
    public class LocalLogControl
    {
        /// <summary>
        /// 根据本地日志列表生成TreeList
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static TreeList SetTreeListByLocalLogList(TreeList treeList)
        {
            treeList.ClearNodes();
            List<LocalLog> localLogList = TxtControl.ReadListFromTxt();
            //遍历工步信息列表
            for (int i = 0; i < localLogList.Count; i++)
            {
                LocalLog localLog = localLogList[i];
                treeList = SetTreeListNodeByLocalLog(localLog, treeList, i);
            }
            return treeList;
        }
        /// <summary>
        /// 根据localLog对象生成TreeList节点
        /// </summary>
        /// <param name="slopeStep"></param>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private static TreeList SetTreeListNodeByLocalLog(LocalLog localLog, TreeList treeList, int i)
        {
            //新增表节点
            TreeListNode tmpNode = treeList.Nodes.Add();
            tmpNode["SerialNumber"] = treeList.Nodes.Count;
            tmpNode["Date"] = localLog.TestATime.ToShortDateString();
            tmpNode["Time"] = localLog.TestATime.ToShortTimeString();
            tmpNode["Record"] = localLog.Record;
            tmpNode["LocalEvent"] = localLog.LocalEvent; 
            treeList.SetNodeIndex(tmpNode, i);
            return treeList;
        }
    }
}
